<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是Cortex-M3存储器系统的一些的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV16-10-存储器系统-01-CortexM3">
<meta property="og:url" content="https://sumumm.github.io/post/6caf1c64.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是Cortex-M3存储器系统的一些的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506194638996.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195402557.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506194933625.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195152880.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195233716.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195554329.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195649606.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201000094.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201208372.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201252943.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201333734.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201402578.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201525794.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201552944.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506194933625.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195152880.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506203822570.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506203904832.png">
<meta property="article:published_time" content="2023-06-04T14:06:44.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.008Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="LV16-STM32开发">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506194638996.png">


<link rel="canonical" href="https://sumumm.github.io/post/6caf1c64.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/6caf1c64.html","path":"post/6caf1c64.html","title":"LV16-10-存储器系统-01-CortexM3"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV16-10-存储器系统-01-CortexM3 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E5%AD%98%E5%82%A8%E5%99%A8%E6%98%A0%E5%B0%84"><span class="nav-text">一、存储器映射  </span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E9%A2%84%E5%AE%9A%E4%B9%89%E7%9A%84%E5%AD%98%E5%82%A8%E5%99%A8%E6%98%A0%E5%B0%84"><span class="nav-text">1. 预定义的存储器映射</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%BB%A3%E7%A0%81%E5%8C%BA%E5%9F%9F512M"><span class="nav-text">2. 代码区域512M</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%86%85%E9%83%A8SRAM%E5%8C%BA%E5%9F%9F512M"><span class="nav-text">3. 内部SRAM区域512M</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E7%89%87%E4%B8%8A%E5%A4%96%E8%AE%BE%E5%8C%BA%E5%9F%9F-512M"><span class="nav-text">4. 片上外设区域 512M</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E4%B8%A4%E4%B8%AA1GB"><span class="nav-text">5. 两个1GB</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E6%9C%80%E5%90%8E%E7%9A%84512M"><span class="nav-text">6. 最后的512M</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E5%AD%98%E5%82%A8%E5%99%A8%E8%AE%BF%E9%97%AE%E5%B1%9E%E6%80%A7"><span class="nav-text">二、存储器访问属性</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E5%AD%98%E5%82%A8%E5%99%A8%E7%9A%84%E7%BC%BA%E7%9C%81%E8%AE%BF%E9%97%AE%E8%AE%B8%E5%8F%AF"><span class="nav-text">三、存储器的缺省访问许可  </span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E4%BD%8D%E5%B8%A6%E6%93%8D%E4%BD%9C"><span class="nav-text">四、位带操作</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%BD%8D%E5%B8%A6%E5%8C%BA%E4%B8%8E%E4%BD%8D%E5%B8%A6%E5%88%AB%E5%90%8D%E5%8C%BA%E5%85%B3%E7%B3%BB"><span class="nav-text">1. 位带区与位带别名区关系</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%BD%8D%E5%B8%A6%E6%93%8D%E4%BD%9C%E4%B8%BE%E4%BE%8B"><span class="nav-text">2. 位带操作举例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E4%BD%8D%E5%B8%A6%E5%86%99%E6%93%8D%E4%BD%9C"><span class="nav-text">2.1 位带写操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E4%BD%8D%E5%B8%A6%E8%AF%BB%E6%93%8D%E4%BD%9C"><span class="nav-text">2.2 位带读操作</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86"><span class="nav-text">3. 基本原理</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E4%BD%8D%E5%B8%A6%E5%88%AB%E5%90%8D%E9%87%8D%E6%98%A0%E5%B0%84"><span class="nav-text">4. 位带别名重映射</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-SRAM%E5%8C%BA"><span class="nav-text">4.1 SRAM区</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E7%89%87%E4%B8%8A%E5%A4%96%E8%AE%BE%E5%8C%BA"><span class="nav-text">4.2 片上外设区</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-%E4%B8%80%E4%B8%AA%E5%AE%9E%E4%BE%8B"><span class="nav-text">4.3 一个实例</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E4%BD%8D%E5%B8%A6%E6%93%8D%E4%BD%9C%E7%9A%84%E5%A5%BD%E5%A4%84"><span class="nav-text">5. 位带操作的好处</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E5%9C%A8C%E8%AF%AD%E8%A8%80%E4%B8%AD%E4%BD%BF%E7%94%A8%E4%BD%8D%E5%B8%A6"><span class="nav-text">6. 在C语言中使用位带</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/6caf1c64.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV16-10-存储器系统-01-CortexM3 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV16-10-存储器系统-01-CortexM3
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-06-04 22:06:44" itemprop="dateCreated datePublished" datetime="2023-06-04T22:06:44+08:00">2023-06-04</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/" itemprop="url" rel="index"><span itemprop="name">01HQ课程体系</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">LV16-STM32开发</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>7k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>25 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是Cortex-M3存储器系统的一些的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">SecureCRT</td>        <td align="left">Version 8.7.2 (x64 build 2214)   -   正式版-2020年5月14日</td>      </tr>    <tr>        <td align="center">开发板</td>        <td align="left">正点原子 i.MX6ULL Linux阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">STM32开发板</td>        <td align="left">正点原子战舰V3(STM32F103ZET6)</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <ul><li>通用</li></ul><table><tr><td align="center">分类  </td><td align="center">网址</td><td align="center">说明</td></tr><tr><td align="center" rowspan="4">官方网站</td><td align="left"><a href="https://www.arm.com/" target="_blank">https://www.arm.com/</a></td><td align="left">ARM官方网站，在这里我们可以找到Cotex-Mx以及ARMVx的一些文档</td></tr><tr>                                            <td align="left"><a href="https://www.st.com/content/st_com/zh.html" target="_blank">https://www.st.com/content/st_com/zh.html</a></td><td align="left">ST官方网站，在这里我们可以找到STM32的相关文档</td></tr><tr>                                            <td align="left"><a href="https://www.stmcu.com.cn/" target="_blank">https://www.stmcu.com.cn/</a></td><td align="left">意法半导体ST中文官方网站，在这里我们可以找到STM32的相关中文参考文档</td></tr><tr>                                            <td align="left"><a href="http://elm-chan.org/fsw/ff/00index_e.html" target="_blank">http://elm-chan.org/fsw/ff/00index_e.html</a></td><td align="left">FatFs文件系统官网</td></tr><tr><td align="center" rowspan="3">教程书籍</td><td align="left"><a href="STM32开发相关资料/01ARM参考资料/ARM Cortex-M3权威指南(中文).pdf" target="_blank">《ARM Cortex-M3权威指南》</a></td><td alirn="left" rowspan="3">ARM公司专家Joseph Yiu（姚文祥）的力作，中文翻译是NXP的宋岩</td></tr><tr>                                            <td align="left"><a href="STM32开发相关资料/01ARM参考资料/ARM Cortex-M0权威指南(中文).pdf" target="_blank">《ARM Cortex-M0权威指南》</a></td></tr><tr>                                            <td align="left"><a href="" target="_blank">《ARM Cortex-M3与Cortex-M4权威指南》</a></td></tr><tr><td align="center" rowspan="4">开发论坛</td><td align="left"><a href="http://47.111.11.73/forum.php" target="_blank">http://47.111.11.73/forum.php</a></td><td align="left">开源电子网，正点原子的资料下载及问题讨论论坛</td></tr><tr>                                            <td align="left"><a href="https://www.firebbs.cn/forum.php" target="_blank">https://www.firebbs.cn/forum.php</a></td><td align="left">国内Kinetis开发板-野火/秉火（刘火良）主持的论坛，现也做STM32和i.MX RT</td></tr><tr>                                            <td align="left"><a href="https://www.amobbs.com/index.php" target="_blank">https://www.amobbs.com/index.php</a></td><td align="left">阿莫（莫进明）主持的论坛，号称国内最早最火的电子论坛，以交流Atmel AVR系列单片机起家，现已拓展到嵌入式全平台，其STM32系列帖子有70W+。</td></tr><tr>                                            <td align="left"><a href="http://download.100ask.net/index.html" target="_blank">http://download.100ask.net/index.html</a></td><td align="left">韦东山嵌入式资料中心，有些STM32和linux的相关资料也可以来这里找。</td></tr><tr><td align="center" rowspan="3">博客参考</td><td align="left"><a href="http://www.openedv.com/" target="_blank">http://www.openedv.com/</a></td><td align="left">开源网-原子哥个人博客</td></tr><tr>                                            <td align="left"><a href="http://blog.chinaaet.com/jihceng0622" target="_blank">http://blog.chinaaet.com/jihceng0622</a></td><td align="left">博主是原Freescale现NXP的现场应用工程师</td></tr><tr>                                            <td align="left"><a href="https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/cortex-m-resources" target="_blank">cortex-m-resources</a></td><td align="left">这其实并不算是一个博客，这是ARM公司专家Joseph Yiu收集整理的所有对开发者有用的官方Cortex-M资料链接（也包含极少数外部资源链接）</td></tr></table><ul><li>STM32</li></ul><table>    <tr><td align="center" rowspan="2">STM32</td><td align="left"><a href="https://doc.embedfire.com/mcu/stm32/f103/hal_general/zh/latest/index.html" target="_blank">STM32 HAL库开发实战指南——基于F103系列开发板</a></td><td align="left">野火STM32开发教程在线文档</td></tr><tr>                                            <td align="left"><a href="https://doc.embedfire.com/mcu/stm32/f103badao/std/zh/latest/index.html" target="_blank">STM32库开发实战指南——基于野火霸道开发板</a></td><td align="left">野火STM32开发教程在线文档</td></tr></table><ul><li>SD卡</li></ul><table>    <tr><td align="left"><a href="https://www.sdcard.org/" target="_blank">SD Association</a></td><td align="left">提供了SD存储卡和SDIO卡系统规范</td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr><td align="left"><a href="https://www.st.com/resource/en/datasheet/stm32f103ze.pdf" target="_blank">STM32F103xx英文数据手册</a></td><td align="left">STM32F103xC/D/E系列的英文数据手册</td></tr>    <tr><td align="left"><a href="https://www.stmcu.com.cn/Designresource/detail/localization_document%20/709978" target="_blank">STM32F103xx中文数据手册</a></td><td align="left">STM32F103xC/D/E系列的中文数据手册</td></tr>    <tr><td align="left"><a href="https://www.st.com/resource/en/reference_manual/rm0008-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf" target="_blank">STM32F10xxx英文参考手册（RM0008）</a></td><td align="left">STM32F10xxx系列的英文参考手册</td></tr>    <tr><td align="left"><a href="https://www.stmcu.com.cn/Designresource/detail/localization_document%20/710001" target="_blank">STM32F10xxx中文参考手册（RM0008）</a></td><td align="left">STM32F10xxx系列的中文参考手册</td></tr>    <tr><td align="left"><a href="https://developer.arm.com/documentation/100165/0201/?lang=en" target="_blank">Arm Cortex-M3 处理器技术参考手册-英文版</a></td><td align="left">Cortex-M3技术参考手册-英文版</td></tr>    <tr><td align="left"><a href="https://www.st.com/resource/en/programming_manual/pm0056-stm32f10xxx20xxx21xxxl1xxxx-cortexm3-programming-manual-stmicroelectronics.pdf" target="_blank">STM32F10xxx Cortex-M3编程手册-英文版(PM0056)</a></td><td align="left">STM32F10xxx/20xxx/21xxx/L1xxxx系列Cortex-M3编程手册-英文版</td></tr>    <tr><td align="left"><a href="https://www.sdcard.org/downloads/pls/" target="_blank">SD卡相关资料——最新版本</a></td><td align="left">有关SD卡的一些资料可以从这里下载</td></tr>    <tr><td align="left"><a href="https://www.sdcard.org/downloads/pls/archives/" target="_blank">SD卡相关资料——历史版本</a></td><td align="left">有关SD卡的一些历史版本资料可以从这里下载，比如后边看的SD卡2.0协议</td></tr>    <tr><td align="left"><a href="./" target="_blank">SD 2.0 协议标准完整版</a></td><td align="left">这是一篇关于SD卡2.0协议的中文文档，还是比较有参考价值的，可以一看</td></tr></table>
              </div>
            </details> 

<p>本篇笔记主要来自于《Cortex-M3权威指南》的第五章存储器系统。其实有一部分概念在后边一篇笔记中才有所体现，比如什么是寄存器？。</p>
<h1 id="一、存储器映射"><a href="#一、存储器映射" class="headerlink" title="一、存储器映射  "></a><font size=3>一、存储器映射  </font></h1><p>CM3 只有一个单一固定的存储器映射。这一点极大地方便了软件在各种 CM3 单片机间的移植。举个简单的例子，各款 CM3 单片机的 NVIC 和 MPU 都在相同的位置布设寄存器，使得它们变得通用。尽管如此， CM3 定出的条条框框是粗线条的，它依然允许芯片制造商灵活地分配存储器空间，以制造出各具特色的单片机产品。存储空间的一些位置用于调试组件等私有外设，这个地址段被称为“ 私有外设区”。私有外设区的组件包括：  </p>
<p>（1）闪存地址重载及断点单元(FPB)</p>
<p>（2）数据观察点单元(DWT)</p>
<p>（3）指令跟踪宏单元(ITM)</p>
<p>（4）嵌入式跟踪宏单元(ETM)</p>
<p>（5）跟踪端口接口单元(TPIU)</p>
<p>（6）ROM 表</p>
<h2 id="1-预定义的存储器映射"><a href="#1-预定义的存储器映射" class="headerlink" title="1. 预定义的存储器映射"></a><font size=3>1. 预定义的存储器映射</font></h2><p>Cortex-M3预定义的存储器映射如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506194638996.png" alt="image-20230506194638996" style="zoom:50%;" />

<p>这个存储器映射只是个粗线条的模板，半导体厂家会提供更展开的图示，来表明芯片中片上外设的具体分布， RAM 与 ROM 的容量和位置信息。  </p>
<h2 id="2-代码区域512M"><a href="#2-代码区域512M" class="headerlink" title="2. 代码区域512M"></a><font size=3>2. 代码区域512M</font></h2><p>CM3 的地址空间是 4GB, 程序可以在代码区，内部 SRAM 区以及外部 RAM 区中执行。但是因为指令总线与数据总线是分开的， 最理想的是把程序放到代码区， 从而使取指和数据访问各自使用自己的总线，并行不悖。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195402557.png" alt="image-20230506195402557" style="zoom:33%;" />

<h2 id="3-内部SRAM区域512M"><a href="#3-内部SRAM区域512M" class="headerlink" title="3. 内部SRAM区域512M"></a><font size=3>3. 内部SRAM区域512M</font></h2><p>内部 SRAM 区的大小是 512MB，用于让芯片制造商连接片上的 SRAM，这个区通过系统总线来访问。在这个区的下部，有一个 1MB 的位带区：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506194933625.png" alt="image-20230506194933625" style="zoom:33%;" />

<p>该位带区还有一个对应的 32MB 的“位带别名(alias)区”，容纳了 8M 个“位变量”（对比 8051 的只有 128 个位）。位带区对应的是最低的 1MB 地址范围，而位带别名区里面的每个字对应位带区的一个比特。位带操作只适用于数据访问，不适用于取指。通过位带的功能，可以把多个布尔型数据打包在单一的字中，却依然可以从位带别名区中，像访问普通内存一样地使用它们。位带别名区中的访问操作是原子的，消灭了传统的“读－改－写”三步曲。位带操作的细节后边再说。  </p>
<h2 id="4-片上外设区域-512M"><a href="#4-片上外设区域-512M" class="headerlink" title="4. 片上外设区域 512M"></a><font size=3>4. 片上外设区域 512M</font></h2><p>地址空间的另一个 512MB 范围由片上外设（的寄存器）使用。这个区中也有一条 32MB的位带别名，以便于快捷地访问外设寄存器。例如，可以方便地访问各种控制位和状态位。要注意的是，外设内不允许执行指令。  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195152880.png" alt="image-20230506195152880" style="zoom:33%;" />

<h2 id="5-两个1GB"><a href="#5-两个1GB" class="headerlink" title="5. 两个1GB"></a><font size=3>5. 两个1GB</font></h2><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195233716.png" alt="image-20230506195233716" style="zoom:33%;" />

<p>这两个 1GB 的范围，分别用于连接外部 RAM 和外部设备，它们之中没有位带。两者的区别在于外部 RAM 区允许执行指令，而外部设备区则不允许。  </p>
<h2 id="6-最后的512M"><a href="#6-最后的512M" class="headerlink" title="6. 最后的512M"></a><font size=3>6. 最后的512M</font></h2><p>最后还剩下 0.5GB 的隐秘地带， CM3 内核的闺房就在这里面，包括了系统级组件，内部私有外设总线 s，外部私有外设总线 s，以及由提供者定义的系统外设。  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195554329.png" alt="image-20230506195554329" style="zoom: 50%;" />

<p>私有外设总线有两条：  </p>
<ul>
<li><p>AHB 私有外设总线，只用于 CM3 内部的 AHB 外设，它们是： NVIC, FPB, DWT 和 ITM。</p>
</li>
<li><p>APB 私有外设总线，既用于 CM3 内部的 APB 设备，也用于外部设备（这里的“外部”是对内核而言）。 CM3 允许器件制造商再添加一些片上 APB 外设到 APB 私有总线上，它们通过 ABP 接口来访问。</p>
</li>
</ul>
<p>NVIC 所处的区域叫做“系统控制空间（ SCS）”，在 SCS 里的还有 SysTick、 MPU 以及代码调试控制所用的寄存器：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195649606.png" alt="image-20230506195649606" style="zoom:50%;" />

<p>最后，未用的提供商指定区也通过系统总线来访问，但是不允许在其中执行指令。CM3 中的 MPU 是选配的，由芯片制造商决定是否配上。</p>
<h1 id="二、存储器访问属性"><a href="#二、存储器访问属性" class="headerlink" title="二、存储器访问属性"></a><font size=3>二、存储器访问属性</font></h1><p>CM3 在定义了存储器映射之外，还为存储器的访问规定了 4 种属性，分别是：<br>（1）可否缓冲(Bufferable)</p>
<p>（2）可否缓存(Cacheable)</p>
<p>（3）可否执行(Executable)</p>
<p>（4）可否共享(Sharable)  </p>
<p>如果配了 MPU，则可以通过它配置不同的存储区，并且覆盖缺省的访问属性。 CM3 片内没有配备缓存，也没有缓存控制器，但是允许在外部添加缓存。通常，如果提供了外部内存，芯片制造商还要附加一个内存控制器，它可以根据可否缓存的设置，来管理对片内和片外 RAM 的访问操作。  </p>
<p>地址空间可以通过另一种方式分为 8 个 512MB 等份：  </p>
<p>（1）代码区（ 0x0000_0000‐ 0x1FFF_FFFF）。该区是可以执行指令的，缓存属性为 WT（“写通”，Write Through），即不可以缓存。此区亦可写数据。在此区上的数据操作是通过数据总线接口的（读数据使用 D‐Code，写数据使用 System），且在此区上的写操作是缓冲的。</p>
<p>（2）SRAM 区（ 0x2000_0000 – 0x3FFF_FFFF）。此区用于片内 SRAM，写操作是缓冲的，并且可以选择 WB‐WA(Write Back, Write Allocated)缓存属性。此区亦可以执行指令，以允许把代码拷贝到内存中执行——常用于固件升级等维护工作。</p>
<p>（3）片上外设区(0x4000_0000 – 0x5FFF_FFFF)。该区用于片上外设，因此是不可缓存的，也不可以在此区执行指令（这也称为 eXecute Never, XN。 ARM 的参考手册大量使用此术语）。</p>
<p>（4）外部 RAM 区的前半段（ 0x6000_0000 ‐ 0x7FFF_FFFF）。该区用于片外 RAM，可缓存（缓存属性为 WB‐WA），并且可以执行指令。</p>
<p>（5）外部RAM区的后半段(0x8000_0000 - 0x9FFF_FFFF)。除了不可缓存(WT)外，同前半段。</p>
<p>（6）外部外设区的前半段(0xA000_0000 - 0xBFFF_FFFF)。用于片外外设的寄存器，也用于多核系统中的共享内存（需要严格按顺序操作，即不可缓冲)。该区也是个不可执行区。</p>
<p>（7）外部外设区的后半段(0xC000_0000 - 0xDFFF_FFFF)。目前与前半段的功能完全一致。</p>
<p>（8）系统区(0xE000_0000 - 0xFFFF_FFFF)。此区是私有外设和供应商指定功能区。此区不可执行代码。系统区涉及到很多关键部位，因此访问都是严格序列化的(不可缓存，不可缓冲)。而供应商指定功能区则是可以缓存和缓冲的。</p>
<blockquote>
<p>写通，写回，与写时申请：</p>
<p>写回(Write Back)：写入的数据先逗留在缓存中，待到必要时再落实到最终目的地，这也是cache 的最基本职能，用于改善数据传送的效率。</p>
<p>写通(Write Through)：写操作“穿透”中途的缓存，直接落入最终的目的地中。可见，写通操作架空了cache，但它使写操作的结果立即生效。这常用于和片上外设或其它处理器共享的内存中，如显卡的显存，片上外设寄存器，以及双核系统中的共享内存。写通操作和C中的“volatile””有密切的联系。</p>
<p>写时申请(Write Allocate)：译者也不太清楚啦~</p>
</blockquote>
<h1 id="三、存储器的缺省访问许可"><a href="#三、存储器的缺省访问许可" class="headerlink" title="三、存储器的缺省访问许可  "></a><font size=3>三、存储器的缺省访问许可  </font></h1><p>CM3有一个缺省的存储访问许可，它能防止使用户代码访问系统控制存储空间，保护NVIC、MPU等关键部件。缺省访问许可在下列条件时生效：</p>
<p>（1）没有配备MPU</p>
<p>（2）配备了MPU，但是MPU被除能</p>
<p>如果启用了MPU，则 MPU可以在地址空间中划出若干个regions，并为不同的 region规定不同的访问许可权限。缺省的存储器访问许可权限如下表：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201000094.png" alt="image-20230506201000094" style="zoom:50%;" />

<p>当一个用户级访问被阻止时，会立即产生一个总线fault。</p>
<h1 id="四、位带操作"><a href="#四、位带操作" class="headerlink" title="四、位带操作"></a><font size=3>四、位带操作</font></h1><h2 id="1-位带区与位带别名区关系"><a href="#1-位带区与位带别名区关系" class="headerlink" title="1. 位带区与位带别名区关系"></a><font size=3>1. 位带区与位带别名区关系</font></h2><p>支持了位带操作后，可以使用普通的加载&#x2F;存储指令来对单一的比特进行读写。在CM3中，有两个区中实现了位带，其中一个是 SRAM 区的最低 1MB 范围  第二个则是片内外设区的最低 1MB 范围。这两个区中的地址除了可以像普通的 RAM 一样使用外，它们还都有自己的“位带别名区”，位带别名区把每个比特膨胀成一个 32 位的字。当通过位带别名区访问这些字时，就可以达到访问原始比特的目的 。</p>
<ul>
<li>位带区与位带别名区的膨胀关系图</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201208372.png" alt="image-20230506201208372" style="zoom:50%;" />

<ul>
<li>下图从另一个侧面演示比特的膨胀对应关系</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201252943.png" alt="image-20230506201252943" style="zoom:50%;" />

<h2 id="2-位带操作举例"><a href="#2-位带操作举例" class="headerlink" title="2. 位带操作举例"></a><font size=3>2. 位带操作举例</font></h2><h3 id="2-1-位带写操作"><a href="#2-1-位带写操作" class="headerlink" title="2.1 位带写操作"></a><font size=3>2.1 位带写操作</font></h3><p>举例：我们要是想要设置地址 0x2000_0000 中的比特 2，则使用位带操作的设置过程如下图所示：  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201333734.png" alt="image-20230506201333734" style="zoom:55%;" />

<p>对应的汇编如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201402578.png" alt="image-20230506201402578" style="zoom: 67%;" />

<h3 id="2-2-位带读操作"><a href="#2-2-位带读操作" class="headerlink" title="2.2 位带读操作"></a><font size=3>2.2 位带读操作</font></h3><p>位带读操作相对简单些  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201525794.png" alt="image-20230506201525794" style="zoom: 67%;" />

<p>对应的汇编为：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506201552944.png" alt="image-20230506201552944" style="zoom:67%;" />

<h2 id="3-基本原理"><a href="#3-基本原理" class="headerlink" title="3. 基本原理"></a><font size=3>3. 基本原理</font></h2><p>位带操作的概念其实多年前就有了，  那还是8051单片机开创的先河。CM3 使用如下术语来表示位带存储的相关地址 ：</p>
<ul>
<li>位带区： 支持位带操作的地址区  </li>
<li>位带别名： 对别名地址的访问最终作用到位带区的访问上（注意：这中间有一个地址映射过程）</li>
</ul>
<p>在位带区中，每个比特都映射到别名地址区的一个字——这是只有LSB有效的字。当一个别名地址被访问时，会先把该地址变换成位带地址。对于读操作，读取位带地址中的一个字，再把需要的位右移到LSB，并把 LSB返回。对于写操作，把需要写的位左移至对应的位序号处，然后执行一个原子的“读一改一写”过程。支持位带操作的两个内存区的范围是：</p>
<ul>
<li>0x2000_0000‐0x200F_FFFF（ SRAM 区中的最低 1MB）</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506194933625.png" alt="image-20230506194933625" style="zoom:33%;" />

<p>对 SRAM 位带区的某个比特，记它所在字节地址为 A，位序号为n（0≤ n ≤ 7）则该比特位在别名区的地址为：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// “*4”表示一个字为 4 个字节，“*8”表示一个字节中有 8 个比特。</span></span><br><span class="line">AliasAddr = <span class="number">0x22000000</span> + ((A - <span class="number">0x2000000</span>) * <span class="number">8</span> + n) * <span class="number">4</span> = <span class="number">0x22000000</span> + (A - <span class="number">0x20000000</span>) * <span class="number">32</span> + n * <span class="number">4</span></span><br></pre></td></tr></table></figure>

<ul>
<li>0x4000_0000‐0x400F_FFFF（片上外设区中的最低 1MB）</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506195152880.png" alt="image-20230506195152880" style="zoom:33%;" />

<p>对 片上外设区的某个比特，记它所在字节地址为 A，位序号为n（0≤ n ≤ 7）则该比特位在别名区的地址为：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// “*4”表示一个字为 4 个字节，“*8”表示一个字节中有 8 个比特。</span></span><br><span class="line">AliasAddr = <span class="number">0x42000000</span> + ((A - <span class="number">0x4000000</span>) * <span class="number">8</span> + n) * <span class="number">4</span> = <span class="number">0x42000000</span> + (A - <span class="number">0x40000000</span>) * <span class="number">32</span> + n * <span class="number">4</span></span><br></pre></td></tr></table></figure>

<h2 id="4-位带别名重映射"><a href="#4-位带别名重映射" class="headerlink" title="4. 位带别名重映射"></a><font size=3>4. 位带别名重映射</font></h2><h3 id="4-1-SRAM区"><a href="#4-1-SRAM区" class="headerlink" title="4.1 SRAM区"></a><font size=3>4.1 SRAM区</font></h3><table>
<thead>
<tr>
<th>位带区</th>
<th>等效别名地址</th>
</tr>
</thead>
<tbody><tr>
<td>0x2000000.0</td>
<td>0x2200000.0</td>
</tr>
<tr>
<td>0x2000000.1</td>
<td>0x2200004.0</td>
</tr>
<tr>
<td>0x2000000.2</td>
<td>0x2200008.0</td>
</tr>
<tr>
<td>……</td>
<td>……</td>
</tr>
<tr>
<td>0x2000000.31</td>
<td>0x220007C.0</td>
</tr>
<tr>
<td>0x2000004.0</td>
<td>0x2200080.0</td>
</tr>
<tr>
<td>0x2000004.1</td>
<td>0x2200084.0</td>
</tr>
<tr>
<td>0x2000004.2</td>
<td>0x2200088.0</td>
</tr>
<tr>
<td>……</td>
<td>……</td>
</tr>
<tr>
<td>0x200FFFFC.31</td>
<td>0x23FFFFFC.0</td>
</tr>
</tbody></table>
<h3 id="4-2-片上外设区"><a href="#4-2-片上外设区" class="headerlink" title="4.2 片上外设区"></a><font size=3>4.2 片上外设区</font></h3><table>
<thead>
<tr>
<th>位带区</th>
<th>等效别名地址</th>
</tr>
</thead>
<tbody><tr>
<td>0x4000000.0</td>
<td>0x4200000.0</td>
</tr>
<tr>
<td>0x4000000.1</td>
<td>0x4200004.0</td>
</tr>
<tr>
<td>0x4000000.2</td>
<td>0x4200008.0</td>
</tr>
<tr>
<td>……</td>
<td>……</td>
</tr>
<tr>
<td>0x4000000.31</td>
<td>0x420007C.0</td>
</tr>
<tr>
<td>0x4000004.0</td>
<td>0x4200080.0</td>
</tr>
<tr>
<td>0x4000004.1</td>
<td>0x4200084.0</td>
</tr>
<tr>
<td>0x4000004.2</td>
<td>0x4200088.0</td>
</tr>
<tr>
<td>……</td>
<td>……</td>
</tr>
<tr>
<td>0x400FFFFC.31</td>
<td>0x43FFFFFC.0</td>
</tr>
</tbody></table>
<h3 id="4-3-一个实例"><a href="#4-3-一个实例" class="headerlink" title="4.3 一个实例"></a><font size=3>4.3 一个实例</font></h3><p>（1）在地址0x20000000处写入0x3355AACC</p>
<p>（2）读取地址0x22000008。本次读访问将读取0x20000000，并提取比特2，值为1。</p>
<p>（3）往地址0x22000008处写0。本次操作将被映射成对地址0x20000000的“读一改一写”操作（原子的)，把比特⒉清 0。</p>
<p>（4）现在再读取0x20000000，将返回0x3355AAC8 ( bit[2]已清零)。</p>
<p>位带别名区的字只有LSB有意义。另外，在访问位带别名区时，不管使用哪一种长度的数据传送指令(字&#x2F;半字&#x2F;字节)，都把地址对齐到字的边界上，否则会产生不可预料的结果。</p>
<h2 id="5-位带操作的好处"><a href="#5-位带操作的好处" class="headerlink" title="5. 位带操作的好处"></a><font size=3>5. 位带操作的好处</font></h2><p>位带操作有什么优越性呢?最容易想到的就是通过GPIO的管脚来单独控制每盏LED的点亮与熄灭。另一方面,也对操作串行接口器件提供了很大的方便(典型如74HC165，CD4094)。总之位带操作对于硬件I&#x2F;O密集型的底层程序最有用处了。</p>
<p>CM3中还有一个称为“bit-bang”的概念，它通常是通过“bit-band”实现的，但是它俩在学术上是两个不同的概念。位带操作还能用来化简跳转的判断。当跳转依据是某个位时，以前必须这样做:（1）读取整个寄存器（2）掩蔽不需要的位（3）比较并跳转。现在只需:（1）从位带别名区读取状态位（2）比较并跳转。使代码更简洁 。</p>
<p>这只是位带操作优越性的初等体现，位带操作还有一个重要的好处是在多任务中，<strong>用于实现共享资源在任务间的“互锁”访问</strong>。多任务的共享资源必须满足一次只有一个任务访问它——亦即所谓的“原子操作”。以前的读一改一写需要3条指令，导致这中间留有两个能被中断的空当。于是可能会出现如下图所示的紊乱危象:</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506203822570.png" alt="image-20230506203822570" style="zoom: 67%;" />

<p>同样的紊乱危象可以出现在多任务的执行环境中。其实，上图所演示的情况可以看作是多任务的一个特例：主程序是一个任务， ISR 是另一个任务，这两个任务并发执行。</p>
<p>通过使用 CM3 的位带操作，就可以消灭上例中的紊乱危象。 CM3 把这个“读－改－写”做成一个硬件级别支持的原子操作，不能被中断，如下图：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-10-%E5%AD%98%E5%82%A8%E5%99%A8%E7%B3%BB%E7%BB%9F-01-CortexM3/img/image-20230506203904832.png" alt="image-20230506203904832" style="zoom:67%;" />



<h2 id="6-在C语言中使用位带"><a href="#6-在C语言中使用位带" class="headerlink" title="6. 在C语言中使用位带"></a><font size=3>6. 在C语言中使用位带</font></h2><p>不幸的是，在 C 编译器中并没有直接支持位带操作。比如， C 编译器并不知道同一块内存能够使用不同的地址来访问，也不知道对位带别名区的访问只对 LSB 有效。欲在 C 中使用位带操作，最简单的做法就是#define 一个位带别名区的地址。例如：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span> DEVICE_REG0      ((volatile unsigned long *) (0x40000000))</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> DEVICE_REG0_BIT0 ((volatile unsigned long *) (0x42000000))</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> DEVICE_REG0_BIT1 ((volatile unsigned long *) (0x42000004))</span></span><br><span class="line"></span><br><span class="line">*DEVICE_REG0 = <span class="number">0xAB</span>; <span class="comment">// 地址访问寄存器</span></span><br><span class="line"></span><br><span class="line">*DEVICE_REG0 = *DEVICE_REG0 | <span class="number">0x2</span>; <span class="comment">// 使用传统方法设置 bit1</span></span><br><span class="line">*DEVICE_REG0_BIT1 = <span class="number">0x1</span>;           <span class="comment">// 通过位带别名地址设置 bit1</span></span><br></pre></td></tr></table></figure>

<p>为简化位带操作，也可以定义一些宏。比如，我们可以建立一个把”位带地址+位序号“转换成别名地址的宏，再建立一个把别名地址转换成指针类型的宏：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//把“位带地址＋位序号”转换成别名地址的宏</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> BITBAND(addr, bitnum) ((addr &amp; 0xF0000000) + 0x2000000 + ((addr &amp; 0xFFFFF) &lt;&lt; 5) + (bitnum &lt;&lt; 2))</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//把该地址转换成一个指针</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> MEM_ADDR(addr) *((volatile unsigned long *) (addr))</span></span><br></pre></td></tr></table></figure>

<p> 在此基础上，我们就可以如下改写代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">MEM_ADDR(DEVICE_REG0) = <span class="number">0xAB</span>; <span class="comment">//使用正常地址访问寄存器</span></span><br><span class="line">MEM_ADDR(DEVICE_REGO) = MEM_ADDR(DEVICE_REGO) | <span class="number">0x2</span>;<span class="comment">// 传统做法</span></span><br><span class="line">MEM_ADDR(BITBAND(DEVICE_REGO, <span class="number">1</span>)) = <span class="number">0x1</span>;            <span class="comment">// 使用位带别名地址</span></span><br></pre></td></tr></table></figure>

<p>注意：当使用位带功能时，要访问的变量必须用 volatile 来定义。因为 C 编译器并不知道同一个比特可以有两个地址。所以就要通过volatile，使得编译器每次都如实地把新数值写入存储器，而不再会出于优化的考虑，在中途使用寄存器来操作数据的复本，直到最后才把复本写回（这和 cache的原理是一样的)。</p>

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/6caf1c64.html">LV16-10-存储器系统-01-CortexM3</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年06月04日 - 22:06</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/6caf1c64.html" title="LV16-10-存储器系统-01-CortexM3">https://sumumm.github.io/post/6caf1c64.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/LV16-STM32%E5%BC%80%E5%8F%91/" rel="tag"><i class="fa fa-tag"></i> LV16-STM32开发</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/dd6fcfa9.html" rel="prev" title="LV16-10-存储器系统-02-STM32">
                  <i class="fa fa-angle-left"></i> LV16-10-存储器系统-02-STM32
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/da1903f3.html" rel="next" title="LV16-09-STM32系统架构">
                  LV16-09-STM32系统架构 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
